package com.example.lx5_27

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.lifecycle.lifecycleScope
import com.alibaba.android.arouter.launcher.ARouter
import com.example.base.mvvm.BaseViewActivity
import com.example.lx5_27.databinding.ActivitySpactivityBinding
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.sql.Time
import java.util.Timer
import java.util.TimerTask
import kotlin.concurrent.timerTask

@AndroidEntryPoint
class SPActivity : BaseViewActivity<ActivitySpactivityBinding>() {

    var timer:Timer? = null
    var num = 5
    override fun initView() {
        timer = Timer()

        lifecycleScope.launch (Dispatchers.IO){
            timer!!.schedule(timerTask{
                  lifecycleScope.launch(Dispatchers.Main){
                      num--
                      if(num == 0){
                          timer!!.cancel()
                          ARouter.getInstance().build("/app/MainActivity").navigation()
                      }
                      binding.tvNum.text = "${num}"+"s"
                  }
            },0,1000)
        }

        binding.tvGo.setOnClickListener {
            timer!!.cancel()
            finish()
            ARouter.getInstance().build("/app/MainActivity").navigation()
        }
    }

    override fun initData() {

    }
}